package com.jiantong.web.open.app.user;

import com.jiantong.common.util.UserUtil;
import com.jiantong.user.ext.LoginUser;
import com.jiantong.user.model.CertificateStation;
import com.jiantong.user.service.CertificateStationReadService;
import com.jiantong.web.core.enums.ExceptionCode;
import io.terminus.boot.rpc.common.annotation.RpcConsumer;
import io.terminus.common.model.Response;
import io.terminus.pampas.openplatform.annotations.OpenBean;
import io.terminus.pampas.openplatform.annotations.OpenMethod;
import io.terminus.pampas.openplatform.exceptions.OPServerException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.List;

/**
 * Created by mz on 22/9/17.
 *
 */
@Slf4j
@OpenBean
public class CertificateStationApis {

    @RpcConsumer
    private CertificateStationReadService certificateStationReadService;

    @OpenMethod(
            key = "find.local.certificate.stations",
            httpMethods = RequestMethod.GET
    )
    public List<CertificateStation> findLocalCertificateStations(){
        LoginUser loginUser = UserUtil.getCurrentUser();

        Response<List<CertificateStation>> response = certificateStationReadService.findByProvinceIdAndCityId(loginUser);

        if(!response.isSuccess()){
            log.error("failed to query list , case = {}",response.getError());
            throw new OPServerException(ExceptionCode.DATA_NOT_FOUND.value(),response.getError());
        }

        return response.getResult();
    }
}
